
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基本信息</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">任务名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="row[title]"
                                           value="" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">任务类型</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="row[type]" required
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择类型', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($type)): foreach ($type as $key=>$item): ?>
                                            <option value="<?= $key ?>"><?= $item ?></option>
                                        <?php endforeach; endif; ?>
                                    </select>

                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">内容 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <!-- 加载编辑器的容器 -->
                                    <textarea id="container" name="row[content]" type="text/plain"></textarea>
                                </div>
                            </div>


                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label">执行周期</label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input type="text" class="tpl-form-input" id="schedule" style="font-size:12px;font-family: Verdana;word-spacing:23px;" name="row[schedule]" value="* * * * *" required  onchange="CheckSchedule(this.value)"/>
                                    </div>

                                </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label"></label>
                                <div class="am-u-sm-9 am-u-end">
                                <div id="schedulepicker">
                <pre><code>*    *    *    *    *
-    -    -    -    -
|    |    |    |    +--- day of week (0 - 7) (Sunday=0 or 7)
|    |    |    +-------- month (1 - 12)
|    |    +------------- day of month (1 - 31)
|    +------------------ hour (0 - 23)
+----------------------- min (0 - 59)</code></pre>
                                    <h5>接下来<input type="number" id="pickdays" class="form-control text-center" value="7" style="display: inline-block;width:80px;">次的执行时间</h5>
                                    <ol id="scheduleresult" class="list-group">
                                    </ol>
                                </div>
                                </div>


                            </div>



                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">最多执行</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="row[maximums]" value="0"  size="6" required>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">开始时间</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="j-laydate-start am-form-field" name="row[begintime]"   required="" >
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">结束时间</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="j-laydate-end am-form-field" name="row[endtime]" value="0" required>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">权重</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="row[weigh]" value="0" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">状态 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="row[status]" value="1" data-am-ucheck checked>启用
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="row[status]" value="4" data-am-ucheck>禁用
                                    </label>
                                </div>
                            </div>
                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>

                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script src="assets/common/plugins/laydate/laydate.js"></script>
<script src="assets/store/js/select.data.js?v=<?= $version ?>"></script>
<script>
    $(function () {

        // 时间选择器
        laydate.render({
            elem: '.j-laydate-start'
            , type: 'datetime'
        });
        // 时间选择器
        laydate.render({
            elem: '.j-laydate-end'
            , type: 'datetime'
        });
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });

    //输入事件  地址：develop/crontab/check_schedule
    function CheckSchedule(value){
        $ajax({
            url : 'develop/crontab/check_schedule',
            type: 'post',
            dataType: 'json',
            data: value,
            success: function (result) {
                if (options.success === $.noop) {
                    result.code === 1 ? $.show_success(result.msg, result.url)
                        : $.show_error(result.msg);
                } else {
                    options.success.call(true, result);
                }

            }
        });
    }

    $(document).on("change", "#pickdays", function () {
        $ajax({
            url: "develop/crontab/get_schedule_future",
            data: {schedule: $("#schedule").val(), days: $(this).val()},
            success:function (data, ret) {
                if (typeof data.futuretime !== 'undefined' && $.isArray(data.futuretime)) {
                    var result = [];
                    $.each(data.futuretime, function (i, j) {
                        result.push("<li class='list-group-item'>" + j + "<span class='badge'>" + (i + 1) + "</span></li>");
                    });
                    $("#scheduleresult").html(result.join(""));
                } else {
                    $("#scheduleresult").html("");
                }
                return false;
            };
    });
    $("#pickdays").trigger("change");
</script>
